# 4.3 Ball Recognition ## 4.3.1 Algorithm ![7](./media/7.png) It determines whether there is an orange ping-pong ball or a green tennis ball in the image. If yes, it returns their coordinates, size and label value. ---------- ## 4.3.2 Classification Label | Label ID | Definition | | :------: | :----------------: | | 1 | ping pong (orange) | | 2 | tennis (green) | Ping pong: ![7](./media/7.png)![image-20250916144905335](./media/image-20250916144905335.png) Tennis: ![8](./media/8.png)![image-20250916144923777](./media/image-20250916144923777.png) ## 4.3.3 Code Blocks 1. ![a36](./media/a36.png) recognizes the detected ball is 'Table Tennis' or 'Tennis'. ![image-20251008142242805](./media/image-20251008142242805.png) ---------- ## 4.3.4 Test Code 1. In the code start-up, set the serial port baud rate to `9600`, and then set the communication mode of the AI vision module to `I2C`, and finally set it to run in `Ball` mode. ![a37](./media/a37.png) 2. The if block determines the number of detections. Only when the number of detections is greater than 0 will the data be output. Note to choose `Ball`. ![a110](./media/a110.png) 3. The serial port outputs the `label` value of the detected ball without wrapping. ![a38](./media/a38.png) 4. ![a36](./media/a36.png) recognizes the detected ball and the serial monitor outputs the ball name. ![a111](./media/a111.png) **Complete code:** ![a39](./media/a39.png) ----------- ## 4.3.5 Test Result After uploading the code, the module will detect the area captured by the camera. If an orange ping pong or a green tennis is detected, it will be recognized, and its label value and name will be displayed on the serial monitor. ![a43](./media/a43.png)